package com.wframe.framework.util;

import java.util.ArrayList;
import java.util.List;

import com.frame.database.JdataBean;
import com.wframe.framework.database.ParmSqlVo;

public class ConversionUtil {

	public static ParmSqlVo arrayToInSql(String[] parms){
		String insql="";
		ParmSqlVo vo=new ParmSqlVo();
		List<String> parmlist=new ArrayList<String>();
		for(String parm:parms){insql+=",?";parmlist.add(parm);}
		vo.setInSql(insql.substring(1,insql.length()));
		vo.setParms(parmlist);
		return vo;
	}
	
	public static ParmSqlVo beanToSql(JdataBean parms){
		String insql="";
		ParmSqlVo vo=new ParmSqlVo();
		List parmlist=new ArrayList();
		Object[] keys=parms.getDataMap().keySet().toArray();
		for(Object key:keys){if(!"".equals(insql))insql+=" and ";insql+=key+"=?";parmlist.add(parms.get(key.toString()));}
		vo.setInSql(insql);
		vo.setParms(parmlist);
		return vo;
	}
}
